<template>
  <div class="mymsg">
    <!-- 个人信息页面 -->
    <div class="my_center">
      <span>用户信息</span>
    </div>
    <!-- 个人信息 -->
    <div class="my_center_detail">
      <div class="top_01">
        <div class="mymsg_top">
          <span>电子邮件:</span>
          <span>{{data[0].user_email}}</span>
          <span>
            <!-- <el-button @click="ChangeEmail" :closeOnClickModal="false"
              >修改</el-button
            > -->
          </span>
        </div>
        <div class="mymsg_top">
          <span>手机号码:</span>
          <span>{{data[0].user_phone}}</span>
          <span>
            <el-button @click="ChangePhone" :closeOnClickModal="false">
              修改
            </el-button>
          </span>
        </div>
      </div>
      <!-- 中间部分 -->
      <div class="my_body">
        <div class="body_01">
          <span>姓名:</span>
          <span>{{data[0].user_name}}</span>
          <span></span>
        </div>
        <div class="body_01">
          <span>证件类型:</span>
          <span>身份证</span>
          <span></span>
        </div>
        <div class="body_01">
          <span>证件号码:</span>
          <span>{{data[0].user_cardId}}</span>
          <span></span>
        </div>
        <div class="body_01">
          <span>生日:</span>
          <span></span>
          <span>
            <el-button @click="dialogFormVisible = true">编辑</el-button>

            <el-dialog
              title="个人信息"
              :visible.sync="dialogFormVisible"
              :close-on-click-modal="false"
            >
              <el-form :model="form">
                <el-form-item label="姓名" :label-width="formLabelWidth">
                  <el-input v-model="form.name" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="身份证类型" :label-width="formLabelWidth">
                  <el-select
                    v-model="form.CardType"
                    placeholder="请选择身份证类型"
                  >
                    <el-option
                      label="中华人民共和国居民身份证"
                      value="居民身份证"
                    ></el-option>
                    <el-option
                      label="港澳台身份证"
                      value="港澳台身份证"
                    ></el-option>
                  </el-select>
                </el-form-item>
                <el-form-item label="身份证号码" :label-width="formLabelWidth">
                  <el-input v-model="form.CardId" autocomplete="off"></el-input>
                </el-form-item>
              </el-form>
              <div slot="footer" class="dialog-footer">
                <el-button @click="dialogFormVisible = false">取 消</el-button>
                <el-button
                  type="primary"
                  @click="ChangeMsg(form.name, form.CardId, form.CardType)"
                  >确 定</el-button
                >
              </div>
            </el-dialog>
          </span>
        </div>
      </div>
      <!-- 驾驶证/驾驶员部分 -->
      <div class="my_footer">
        <div class="footer_01">
          <span>驾驶证认证:</span>
          <span>
            <el-upload
              class="upload-demo"
              ref="upload"
              action="http://localhost:3000/user/uploadimg"
              :on-preview="handlePreview"
              :on-remove="handleRemove"
              :auto-upload="false"
              :on-success="uploadsuccess"
              :data="resdata"
              :file-list="fileList"
              :on-progress="progress"
              :limit="2"
              multiple
            >
              <el-button slot="trigger" size="small" type="primary"
                >选取文件</el-button
              >
              <el-button
              
                style="margin-left: 10px"
                size="small"
                type="success"
                @click="submitUpload"
                >上传到服务器</el-button
              >
              <div slot="tip" class="el-upload__tip">
                只能上传jpg/png文件，且不超过500kb
              </div>
            </el-upload>
          </span>
          <span></span>
        </div>
        <div class="footer_01">
          <span>紧急联系人:</span>
          <span>{{data[0].user_urgent_name}}</span>
          <span>
            <el-button @click="Visible = true">编辑</el-button>
            <el-dialog
              title="填写紧急联系人信息"
              :visible.sync="Visible"
              :close-on-click-modal="false"
            >
              <el-form :model="urgen">
                <el-form-item
                  label="紧急联系人姓名"
                  :label-width="formLabelWidth"
                >
                  <el-input v-model="urgen.name" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item
                  label="紧急联系人电话"
                  :label-width="formLabelWidth"
                >
                  <el-input v-model="urgen.phone" autocomplete="off"></el-input>
                </el-form-item>
              </el-form>
              <div slot="footer" class="dialog-footer">
                <el-button @click="Visible = false">取 消</el-button>
                <el-button
                  type="primary"
                  @click="ChangeUrgen(urgen.name, urgen.phone)"
                  >确 定</el-button
                >
              </div>
            </el-dialog>
          </span>
        </div>
        <div class="footer_01">
          <span>紧急联系人电话:</span>
          <span>{{data[0].user_urgent_phone}}</span>
          <span></span>
        </div>
      </div>
      <a href="javascript:;" >
        
        <el-button type="text" @click="FormVisible = true">修改密码</el-button>

        <el-dialog title="修改密码" :visible.sync="FormVisible">
          <el-form :model="user">
            <el-form-item label="输入旧密码" :label-width="formLabelWidth">
              <el-input v-model="user.oldpwd" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="输入新密码" :label-width="formLabelWidth">
              <el-input v-model="user.newpwd" autocomplete="off"></el-input>
            </el-form-item>
          </el-form>
          <div slot="footer" class="dialog-footer">
            <el-button @click="FormVisible = false">取 消</el-button>
            <el-button type="primary" @click="ChangePwd(user.oldpwd,user.newpwd)"
              >确 定</el-button
            >
          </div>
        </el-dialog>
      </a>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
       fileList:[],
      dialogFormVisible: false,
      FormVisible: false, //修改密码
      Visible: false,
      resdata:{
        Uid:sessionStorage.getItem('UserID')
      },
      user: {
        oldpwd: "",
        newpwd: "",
      },
      form: {
        name: "",
        CardType: "",
        CardId: "",
      },
      urgen: {
        name: "",
        phone: "",
      },
      formLabelWidth: "120px",
    };
  },
  props:['data'],
  mounted () {
    console.log(this.data)
  },
  methods: {
    //修改密码
    ChangePwd(O,N){
      this.FormVisible=false
      // console.log('后台修改密码')
      this.user.oldpwd=""
      this.user.newpwd=""
      // console.log(O,N)
    },
    //填写紧急联系人
    ChangeUrgen(n, p) {
      this.Visible = false;
      // console.log("紧急联系人");
      // console.log(n, p);
      let Uid= sessionStorage.getItem('UserID')
      let params = `urgent_name=${n}&urgent_phone=${p}&Uid=${Uid}`
      this.axios.post('/user/updateurgent',params)
      .then(res => {
        // console.log(res)
        this.data=res.data.data
      })
    },
    // 填写个人信息
    ChangeMsg(N, I, T) {
      this.dialogFormVisible = false;
      // console.log("提交数据");
      // console.log(N, I, T);
      let Uid= sessionStorage.getItem('UserID')
      let params = `name=${N}&carid=${I}&Uid=${Uid}`
      this.axios.post('/user/updateuser',params)
      .then(res => {
        console.log(res.data.data[0].user_cardId)
        this.data=res.data.data
        // this.form.CardId=res.data.data[0].user_cardId
      })
    },
    progress(event,file,filelist){
      // console.log(event)
      // console.log(file)
      // console.log(filelist)
    },
    //上传成功
    uploadsuccess(req,file,filelist){
      // console.log(req)
      // console.log(file)
      // console.log(filelist)
    },
    // 上传图片
    submitUpload(event) {
      event.preventDefault();
      this.$refs.upload.submit();
      // console.log(this.fileList);
      // console.log(file.filename);
    },
    handleRemove(file, fileList) {
      // console.log(file, fileList);
    // console.log(file.name)
    },
    handlePreview(file) {
      // console.log(file);
    },
    // 修改手机号
    ChangePhone() {
      this.$prompt("请输入要修改的手机号", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        inputPattern: /^1[3-9]\d{9}$/,
        inputErrorMessage: "手机格式不正确",
      })
        .then(({ value }) => {
          // console.log("去后台修改手机");
          let Uid = sessionStorage.getItem('UserID')
          let params = `phone=${value}&Uid=${Uid}`
          this.axios.post('/user/updatephone',params)
          .then(res => {
            this.data=res.data.data
          })
          // console.log(value);
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "取消修改",
          });
        });
    },
    // 修改邮箱号
    ChangeEmail() {
      this.$prompt("请输入要修改的邮箱号", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        inputPattern:
          /[\w!#$%&'*+/=?^_`{|}~-]+(?:\.[\w!#$%&'*+/=?^_`{|}~-]+)*@(?:[\w](?:[\w-]*[\w])?\.)+[\w](?:[\w-]*[\w])?/,
        inputErrorMessage: "邮箱格式不正确",
      })
        .then(({ value }) => {
          // console.log("去后台修改邮箱号");
          // console.log(value);
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "取消修改",
          });
        });
    },
  },
};
</script>
<style src="../assets/css/mymsg.css" scoped></style>

<style lang="scss" scoped>
</style>
